package com.sakura.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.orm.hibernate4.HibernateTemplate;
import org.springframework.stereotype.Repository;

import com.sakura.dao.LoginDao;
import com.sakura.entity.SakuraUser;

@Repository
public class LoginDaoImpl implements LoginDao{

	@Resource
	private HibernateTemplate hibernateTemplate;
	
	@Override
	public List<SakuraUser> queryUserList() {
		List<SakuraUser> userList = hibernateTemplate.loadAll(SakuraUser.class);
		return userList;
	}

	@Override
	public boolean autoUser(String username, String password) {
		SakuraUser sakuraUser = hibernateTemplate.get(SakuraUser.class, username);
		if (sakuraUser != null) {
			if (password.equals(sakuraUser.getPassWord())) {
				return true;
			} else {
				return false;
			}
		} else {
			return false;
		}
	}
	
	@Override
	public void registerUser(SakuraUser sakuraUser) {
		hibernateTemplate.save(sakuraUser);
	}

	public HibernateTemplate getHibernateTemplate() {
		return hibernateTemplate;
	}

	public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
		this.hibernateTemplate = hibernateTemplate;
	}
}
